%{
       #define YYSTYPE float
       #include <math.h>
       #include <ctype.h>
       #include <stdio.h>
       int yylex (void);
       void yyerror (char const *);
%}

%token NUM

%%
input:
     /* empty */
     | input line
     ;

line:
     '\n'
     | exp '\n'      { printf ("%.2f\n", $1); }
     ;

     exp:
       NUM           { $$ = $1;           }
     | '+' exp exp   { $$ = $2 + $3;      }
     | '-' exp exp   { $$ = $2 - $3;      }
     | '*' exp exp   { $$ = $2 * $3;      }
     | '/' exp exp   { $$ = $2 / $3;      }
     ;
%%

int main (void)
     {
       return yyparse ();
     }

int yylex(){
       int c;
       while ((c = getchar ()) == ' ' || c == '\t')
         continue;
       if (c == '.' || isdigit (c))
         {
           ungetc (c, stdin);
           scanf ("%f", &yylval);
           return NUM;
         }
       if (c == EOF)
         return 0;
       return c;

}

void yyerror(char const * s){
    fprintf(stderr, "unrecognized tokens: %s\n", s);
}

